package com.gin.kotlin.no_gay_alliance.model

import android.os.Parcelable
import com.gin.nga.enums.ForumType
import com.gin.nga.response.forum.ForumInfo
import kotlinx.parcelize.Parcelize

/**
 * 版面搜索结果
 * @property entry 版面或合集入口
 * @property parent 父版面入口
 * @constructor
 */
@Parcelize
data class ForumSearchResultModel(
    var entry: ForumEntryModel,
    var parent: ForumEntryModel? = null,
) : Parcelable {
    constructor():this(ForumEntryModel())
    constructor(forumInfo: ForumInfo) : this( ForumEntryModel().also {
        it.type = if (forumInfo.colTid?.takeIf { i->i>0 } != null) ForumType.COL else ForumType.FORUM
        it.entryId = forumInfo.colTid?.takeIf { i->i>0 } ?: forumInfo.forumId ?:0
        it.name = forumInfo.name?:""
        it.icon = forumInfo.getBigIconUrl()?:""
        it.remark = forumInfo.description
    }) {
        val parent = forumInfo.parent ?:return
        this.parent = ForumEntryModel().also {
            it.type =  ForumType.FORUM
            it.entryId = parent.forumId ?:0
            it.name = parent.name?:""
            it.icon = parent.getBigIconUrl()?:""
            it.remark = parent.description
        }
    }

}
